###############################################################################
# Globals #####################################################################
###############################################################################
__version__ = '0.0.1'
__date__ = 'Date: 2011/01/012'
__author__ = 'Bart Robinson <bartrobinson76@yahoo.com>'
__doc__ = '''
Particle class.
'''
__all__ = ['particle']

###############################################################################
# Imports #####################################################################
###############################################################################

from pycgx.math.vectors.vector3 import vector3
from pycgx.physics.physics import *

###############################################################################
# Classes and Methods #########################################################
###############################################################################

###############################################################################
# Particle
#

class particle():
	
	def __init__(self, translation = vector3(), rotation = vector3(), scale = vector3([1.0, 1.0, 1.0])):
		# Initial state
		self.initial_translation = translation
		self.initial_rotation = rotation
		self.initial_scale = scale
		
		self.initial_translational_velocity = vector3()
		self.initial_rotational_velocity = vector3()
		self.initial_scalar_velocity = vector3()
		
		self.initial_translational_acceleration = vector3()
		self.initial_rotation_acceleration = vector3()
		self.initial_scalar_acceleration = vector3()
		
		self.initial_translational_momentum = vector3()
		self.initial_rotational_momentum = vector3()
		self.initial_scalar_momentum = vector3()
		
		self.initial_translational_impulse = vector3()
		self.initial_rotational_impulse = vector3()
		self.initial_scalar_impulse = vector3()
		
		# Previous state
		self.previous_translation
		self.previous_rotation
		self.previous_scale
		
		self.previous_translational_velocity
		self.previous_rotational_velocity
		self.previous_scalar_velocity
		
		self.previous_translational_acceleration
		self.previous_rotational_acceleration
		self.previous_scalar_acceleration
		
		self.previous_translational_momentum
		self.previous_rotational_momentum
		self.previous_scalar_momentum
		
		self.previous_translational_impulse
		self.previous_rotational_impulse
		self.previous_scalar_impulse
		
		# Physical properties
		self.mass = 1.0
		self.elasticity = 0.0
		self.friction = 0.0
		
		self.charge = 0.0
		self.temperature = 0.0
		
		# Temporal properties
		self.birthdate = 0.0
		self.age = 0.0
		
		# Setup Current State
		self.update()
		
	def update(self):
		# Velocity
		self.previous_translational_velocity = self.translational_velocity
		self.translational_velocity = self.translation - self.previous_translation
		self.previous_rotational_velocity = self.rotational_velocity
		self.rotational_velocity = self.rotation - self.previous_rotation
		self.previous_scalar_velocity = self.scalar_velocity
		self.scalar_velocity = self.scale - self.previous_scale
		# Acceleration
		self.previous_translational_acceleration = self.translational_acceleration
		self.translational_acceleration = self.translational_velocity - self.previous_translation_velocity
		self.previous_rotational_acceleration = self.rotational_acceleration
		self.rotational_acceleration = self.rotational_velocity - self.previous_rotation_velocity
		self.previous_scalar_acceleration = self.scalar_acceleration
		self.scalar_acceleration = self.scalar_velocity - self.previous_scalar_velocity
		# Momentum
		self.previous_translational_momentum = self.translational_momentum
		self.translational_momentum = self.translational_velocity * self.mass
		self.previous_rotational_momentum = self.rotational_momentum
		self.rotational_momentum = self.rotational_velocity * self.mass
		self.previous_scalar_momentum = self.scalar_momentum
		self.scalar_momentum = self.scalar_velocity * self.mass
		# Impulse
		self.previous_translational_impulse = self.translational_impulse
		self.translational_impulse = self.translational_momentum - self.previous_translational_momentum
		self.previous_rotational_impulse = self.rotational_impulse
		self.rotational_impulse = self.rotational_momentum -self.previous_rotational_momentum
		self.previous_scalar_impulse = self.scalar_impulse
		self.scalar_impulse = self.scalar_momentum - self.previous_scalar_momentum
		
	def __getattr__(self, name):
		if name == "translational_velocity":
			return self.translation - self.previous_translation
		elif name == "rotational_velocity":
			return self.rotation - self.previous_rotation
		elif name == "scalar_velocity":
			return self.scale - self.previous_scale
		elif name == "translational_acceleration":
			return self.translational_velocity - self.previous_translational_velocity
		elif name == "rotational_acceleration":
			return self.rotational_velocity - self.previous_rotational_velocity
		elif name == "scalar_acceleration":
			return self.scalar_velocity - self.previous_scalar_velocity
		else:
			pass